package com.spring.gll.utils;

import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

import java.io.File;
import java.io.FileInputStream;

public class DownUtil {
    public static ResponseEntity<byte[]> down(String fileName) throws Exception {
        String path = "E:/"+File.separator+fileName;
        File file = new File(path);
        FileInputStream is = new FileInputStream(file);
        byte[] bytes = new byte[is.available()];
        is.read(bytes);
        HttpHeaders headers = new HttpHeaders();
        headers.add("content-Disposition",
                "attchement;filename="+file.getName());
        HttpStatus status = HttpStatus.OK;
        ResponseEntity<byte[]> responseEntity = new ResponseEntity<byte[]>(bytes, headers, status);
        return responseEntity;
    }

}
